package sample.com.imagecompress.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.github.chrisbanes.photoview.PhotoView;

import java.util.List;

/**
 * Created by dws on 2018/4/2.
 */

public class PhotoViewPagerAdapter extends PagerAdapter {

    private List<Uri> mList;
    private Context mContext;

    public PhotoViewPagerAdapter(Context context, List<Uri> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        //return super.instantiateItem(container, position);
        PhotoView photoView = new PhotoView(mContext);
        photoView.setImageURI(mList.get(position));
        container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        return photoView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //container.removeView(container.getChildAt(position));
        container.removeView((View) object);
    }
}
